import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;


public class Database {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws SQLException,ClassNotFoundException,IOException
	{
		int ch;
		do
		{
			//Register the Driver
			Class.forName("oracle.jdbc.driver.OracleDriver");
			
			//Establishing the connection
			Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "dasta99");
			ch=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice:"));
			
			switch(ch)
			{
			case 1:
				//Using prepared statement we can insert and modify and delete the data
				PreparedStatement ps=con.prepareStatement("insert into netenrich values(?,?)");
				int rollno;
				String name;
				rollno=Integer.parseInt(JOptionPane.showInputDialog("Enter the rollno:"));
				name=JOptionPane.showInputDialog("Enter the name:");
				ps.setInt(1,rollno);
				ps.setString(2,name);
				ps.executeUpdate();
				break;
			case 2:
				//Created the statement
				Statement s1=con.createStatement();
				
				//To retrive the data from the table//To retrive the data from the table
				ResultSet rs1=s1.executeQuery("select * from netenrich");
				System.out.println("RNO NAME" );
				while(rs1.next())
				{
					System.out.println(rs1.getInt(1) + " " + rs1.getString(2));
				}
				
				break;
			case 3:
				System.out.println("Invali Choice....");
				break;
			}
			
			//Closing the JDBC connection
			con.close();
		}while(ch!=3);

	}

}
